﻿CREATE Procedure s_MenuArriveMsg
	@LoanID int,
	@User varchar(50)
As

--EXEC sh_Debug_Put 's_MenuArriveMsg<>@LoanID:$0,@User:$1',@LoanID,@User

DECLARE @Subject varchar(512)

DECLARE @Text nvarchar(4000)

SELECT @Subject = dbo.sprintf3('Loan $0 ($1) arrived in $2 from $3 .', v_LoanInfo.LoanID, 
               t_Borrower.FirstName + ' ' + t_Borrower.LastName, MenuPath,dbo.MenuPathByID(dbo.Loan_Menus_Prev(@LoanID))),
               @Text = dbo.sprintf1('Menu:$1'+CHAR(13)+dbo.config_URL_ShowLoan()+'$0', v_LoanInfo.LoanID,MenuPath)
FROM  v_LoanInfo
INNER JOIN t_Loan ON v_LoanInfo.LoanID = t_Loan.ID
INNER JOIN t_Borrower ON t_Borrower.LoanID = t_Loan.ID
INNER JOIN v_Menu ON t_Loan.MenuID = v_Menu.MenuID
WHERE (t_Loan.ID = @LoanID) AND t_Borrower.Pos = 0

EXEC s_Mail @User,@Subject,@Text


